// source --> https://sikayethaberleri.com/wp-content/plugins/EsenWpMobil/themes/EsenMobile/js/is.js?ver=2.0
(function(root, factory){
"use strict";
if (typeof define === "function" && define.amd) {
define(["jquery"], factory);
} else if (typeof exports === "object") {
factory(require("jquery"));
} else {
factory(root.jQuery);
}
})(this, function($) {
"use strict";
$.fn.cleverInfiniteScroll = function(options) {
var windowHeight = (typeof window.outerHeight !== "undefined") ? Math.max(window.outerHeight, $(window).height()) : $(window).height(),
defaults = {
contentsWrapperSelector: "#ic_kapsayici",
contentSelector: ".icerik_enkap",
nextSelector: "#sonrakiposta",
loadImage: "",
offset: windowHeight,
}, settings = $.extend(defaults, options);
var generateHiddenSpans = function(_title, _path) {
return "" + _title + "" + _path + "";
},
setTitleAndHistory = function(_title, _path) {
// Set history
history.pushState(null, _title, _path);
// Set title
$("title").html(_title);
},
changeTitleAndURL = function(_value) {
// value is an element of a content user is seeing
// Get title and path of the article page from hidden span elements
var title = $(_value).children(".hidden-title:first").text(),
path = $(_value).children(".hidden-url:first").text();
if($("title").text() !== title) {
// If it has changed
$(settings.contentSelector).removeClass("active");
$(_value).addClass("active");
setTitleAndHistory(title, path);
}
};
var title = $("title").text(),
path = $(location).attr("href"),
documentHeight = $(document).height(),
threshold = settings.offset,
$contents = $(settings.contentSelector);
// Set hidden span elements and history
$(settings.contentSelector + ":last").append(generateHiddenSpans(title, path));
$(settings.contentSelector).addClass("active");
setTitleAndHistory(title, path);
var lastScroll = 0, currentScroll;
$(window).scroll(function() {
// Detect where you are
window.clearTimeout($.data("this", "scrollTimer"));
$.data(this, "scrollTimer", window.setTimeout(function() {
// Get current scroll position
currentScroll = $(window).scrollTop();
// Detect whether it's scrolling up or down by comparing current scroll location and last scroll location
if(currentScroll > lastScroll) {
// If it's scrolling down
$contents.each(function(key, value) {
if($(value).offset().top + $(value).height() > currentScroll) {
// Change title and URL
changeTitleAndURL(value);
// Quit each loop
return false;
}
});
} else if(currentScroll < lastScroll) {
// If it's scrolling up
$contents.each(function(key, value) {
if($(value).offset().top + $(value).height() - windowHeight / 2 > currentScroll) {
// Change title and URL
changeTitleAndURL(value);
// Quit each loop
return false;
}
});
} else {
// When currentScroll == lastScroll, it does not do anything because it has not been scrolled.
}
// Renew last scroll position
lastScroll = currentScroll;
}, 200));
if($(window).scrollTop() + windowHeight + threshold >= documentHeight) {
// If scrolling close to the bottom
// Getting URL from settings.nextSelector
var $url = [$(settings.nextSelector).attr("href")];
$(settings.nextSelector).remove();
if($url[0] !== undefined) {
// If the page has link, call ajax
if(settings.loadImage !== "") {
$(settings.contentsWrapperSelector).append("");
}
$.ajax({
url: $url[0],
dataType: "html",
success: function(res) {
// Get title and URL
title = $(res).filter("title").text();
path = $url[0];
// Set hidden span elements and history
$(settings.contentsWrapperSelector).append($(res).find(settings.contentSelector).append(generateHiddenSpans(title, path)));
if($(res).find(settings.contentSelector).find(settings.nextSelector).length === 0){
//If there is no nextSelector in the contentSelector, get next Slecter from response and append it.
$(settings.contentsWrapperSelector).append($(res).find(settings.nextSelector));
}
documentHeight = $(document).height();
$contents = $(settings.contentSelector);
$("#cis-load-img").remove();
}
});
}
}
}); //scroll
return (this);
}; //$.fn.cleverInfiniteScroll
});